package com.qiangesoft.blog.controller.web;

import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.core.pojo.vo.ArticleInfoVO;
import com.qiangesoft.blog.core.pojo.vo.BlogSourceSimpleVO;
import com.qiangesoft.blog.core.pojo.vo.SourceInfoVO;
import com.qiangesoft.blog.core.service.IBlogSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 源码 前端控制器
 * </p>
 *
 * @author qiange
 * @since 2023-06-08
 */
@Api(tags = "源码管理")
@RestController
@RequestMapping("/api/source")
@RequiredArgsConstructor
public class ApiBlogSourceController {

    private final IBlogSourceService blogSourceService;

    @ApiOperation("通过下载量查询源码")
    @GetMapping("/listByDownload")
    public List<BlogSourceSimpleVO> listTopDownload(@RequestParam(required = false, defaultValue = "5") Integer limit) {
        return blogSourceService.listTopDownloadSource(limit);
    }

    @GetMapping
    @ApiOperation("源码列表")
    public PageResultVO<SourceInfoVO> listSource(@Validated PageQuery pageQuery) {
        return blogSourceService.listSource(pageQuery);
    }

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "源码详情")
    public ArticleInfoVO getSource(@PathVariable Long id) {
        return blogSourceService.getSource(id);
    }
}

